<?php
/*
 * Simple forum relization, (c) Taras Kudla, 2009
 *
 * Azaria project
 *
 */
class mod_forum
	{
	
	/* Functions overview 
	
	------TOPICS-----
	-- Add Topic Admin
	-- Delete Topic Admin
	-- Get Topics
	------THEMES-----
	-- Add Themes
	-- Delete Themes Admin
	-- Get Themes Per Topic
	-- Get Themes Per Topic Admin
	------MESSAGES----
	-- Add Message
	-- Delete Message
	-- Get Messages Per Theme
	-- Get Messages Per Theme Admin
	-- Delete Message Admin
	------OTHER-----
	 * 
	-- Get WAY

	 * Sql Tables . works With Mysql Only
	 * table
	 *  id , name, creaed, views
	 * table 2
	 * id , name, topic_id, created , views, owner
	 * table3
	 * 
	 * id, message, created, theme_id, owner, 
	 *
	*/
	
	private $System = null;

	private $lang	= null;

	private $table	= "mod_forum_topics";

	private $table2 = "mod_forum_themes";
	
	private $table3 = "mod_forum_messages";

	private $table4 = "mod_forum_config";

	private $DefaultLanguage = "en";

	private $Languages = array("ru","en","ua");

	private $messagesPerPage=5;


	function __construct(init & $s)
		{
		
		$this->System=&$s;

		$this->System->lang->setModuleLanguage("forum",$this->Languages,$this->DefaultLanguage,$this->lang);

		$this->LoadForumConfiguration();
		}

	private function A($a)
		{

		return $this->System->base->CheckAccess("forumrich",$a);
		}

	private function B($b)
		{

		return $this->System->base->GetHash("forumrich",$b);
		}

	private function C($c,$name)
		{
			if($this->System->base->CheckAccess("users","GetUser"))
				{
					return $this->System->base->BuildActionLink($this->System->base->GetHash("users","GetUser"),"user=".$c,$name);
				}
			else return $name;


		}

	/*
	 * This module some simple function for board principies
	 *
	 * adding messages
	 * adding themes
	 *
	 * full administration
	 */

    /* Topics */

    public function AddTopicAdmin()
        {
			$f["title"]="MAKE A TOPIC";

			$f["options"]=array("action"=>$this->B("AddTopicAdmin"),"method"=>"post");

			$f["input"][0]=array("title"=>"Topic Name","type"=>"text","size"=>"30","name"=>"topicname");

			$f["input"][1]=array("name"=>"Submit","value"=>"Add","type"=>"Submit");

		if($this->System->checkPOST("topicname","Submit"))
			{
				$name=$this->System->toSafe($_POST["topicname"],1);

				$this->System->dbo->insert($this->table, array("name"=>$name,"created"=>date("YmdHis"),"views"=>0));

				return $this->System->base->BuildActionLink("forum-gettopicsadmin",null,"Topic Created. To List");
			}

		else return $this->System->base->FormGenerator($f);

        }

	private function ForumHeader()
		{
			$s="<table width='".$this->width."' cellspacing='0' cellpadding='0' id='forumheadertable'>
			<tr><td id='tableheader'>".$this->lang->get(0)."</td></tr><tr><td id='subtableheader'>".$this->lang->get(1)." ".$this->System->user->GetUserID()." ".$this->System->base->BuildActionLink("forum-addtheme",null,"<b>".$this->lang->get(2)."</b>")."</td></tr></table><br>";

		return $s;
		}



    public function DeleteTopicAdmin()
        {
			if(isset($_GET["topic"]) && is_numeric($_GET["topic"]))
				{
				$topic=$this->System->toSafe($_GET["topic"],1);

					$f["title"]="Do you realy want to delete this topic (id".$topic.") ?";
					
					$f["options"]=array("action"=>$this->B("DeleteTopicAdmin"),"method"=>"post");

					$f["input"][0]=array("type"=>"Submit","name"=>"Submit","value"=>"Yes");

					$f["input"][1]=array("type"=>"hidden","name"=>"topic","value"=>$topic);

					if($this->System->checkPOST("topic","Submit"))
						{
							$this->System->dbo->delete($this->table," where id='".$topic."'");

							$this->System->dbo->delete($this->table3," where theme_id IN (select id from themes where topic_id='".$topic."' ) ");

							$this->System->dbo->delete($this->table2," where topic_id='".$topic."' ");

							return $this->System->base->BuildActionLink("forum-gettopicsadmin",null,"Topic Deleted. To List");
						}
					else return $this->System->base->FormGenerator($f);
				}

			else return "Please specify topic to be deleted )";
        }

    public function GetTopics()
         {
			 $q=$this->System->dbo->select($this->table,"id,name,views"," order by created desc");

			 if(count($q)==0)return "".$this->lang->get(3)."";

			 $i=0;

			 $s="<table width='".$this->width."' cellspacing='0' cellpadding='0'>";

			 while($i<count($q))
				{
					$_=$this->System->dbo->select($this->table2,"COUNT(*)"," where topic_id='".$q[$i]["id"]."'");

					$s.="<tr><td colspan='4'><div id='tableheader'>".$this->System->base->BuildActionLink("forum-getthemes","topic=".$q[$i]["id"],$q[$i]["name"])."</div></td></tr><tr><td colspan='4'><div id='subtableheader'>".$this->lang->get(4)." ".$_[0]["COUNT(*)"]."</div></td></tr>";

					$__=$this->System->dbo->select($this->table2,"id,name"," where topic_id='".$q[$i]["id"]."' order by created desc limit 3 offset 0");

					$j=0;

					while($j<count($__))
						{
							if($j==0)
							$s.="<tr><td id='subtheme'></td><td id='subtheme'></td><td  id='subtheme'>".$this->lang->get(5)."</td><td  id='subtheme'>".$this->lang->get(6)."</td></tr>";

							$m=$this->System->dbo->select($this->table3,"COUNT(*)"," where theme_id='".$__[$j]["id"]."'");

							$m1=$this->System->dbo->select($this->table3,"message,created","where theme_id='".$__[$j]["id"]."' order by created desc limit 0,1");

							$s.="<tr><td id='subtheme' align='center'><img src='".$this->imagePath."th.png' border='0' /></td><td  id='subtheme'>".$this->System->base->BuildActionLink("forum-getmessages","thread=".$__[$j]["id"],$__[$j]["name"])."</td><td  id='subtheme'>".$m[0]["COUNT(*)"]."</td><td  id='subtheme'>".(count($m1)>0?"&rarr; ".$m1[0]["created"]:$this->lang->get(7))."</td></tr>";

							$j++;
						}

					$s.="<tr><td colspan='4' id='endtable'>&nbsp;</td></tr>";

					$i++;
				}
				
				return $this->ForumHeader().$s."</table>";
			 }

	
	public function GetTopicsAdmin()
		{
			$q=$this->System->dbo->select($this->table,"name,id,views,created","");

			$i=0;

			$_="<table>";

			if(count($q)==0)return "Topic Not Found";

			while($i<count($q))
				{
					$_.="<tr><td>".$this->System->base->BuildActionLink("forum-getthemesadmin","topic=".$q[$i]["id"],$q[$i]["name"])."</td><td>".$q[$i]["created"]."</td><td>".$this->System->base->BuildActionLink("forum-deletetopicadmin","topic=".$q[$i]["id"],"[ Delete ]")."</td></tr>";

					$i++;
				}
			return $_."</table>";
		}

	/* THEMES */

	private function topicSelection()
		{
			$q=$this->System->dbo->select($this->table,"id,name","");

			$s="<select name='topic' class='input' multiple>";

			$t=(isset($_GET["topic"])?$_GET["topic"]:0);

			$i=0;

			while($i<count($q))
				{
					$s.="<option value='".$q[$i]["id"]."' ".($t==$q[$i]["id"]?"selected":null).">- ".$q[$i]["name"]."</option>";

					$i++;
				}
			return $s."</select>";
		}

	private function MyThemes()
		{
			$q=$this->System->dbo->select($this->table2,"id,name,created"," where author='".$this->System->user->GetUserID()."' order by topic_id ");

			$s="<table width='95%' cellspacing='0' cellpadding='0'>";

			$s.="<tr><td colspan='4' id='tableheader'>".$this->lang->get(8)."</td></tr>";

			if(count($q)==0)
			$s.="<tr><td colspan='4' id='subtableheader'>".$this->lang->get(9)."</td></tr>";

			$i=0;
			while($i<count($q))
				{
					$s.="<tr><td id='subtableheader' width='15%'><img src='img/th.png' border='0' /></td><td id='subtableheader'  width='40%'>".$this->System->base->BuildActionLink("forum-getmessages","thread=".$q[$i]["id"],$q[$i]["name"])."</td><td id='subtableheader'  width='20%'>&rarr; ".$q[$i]["created"]."</td><td id='subtableheader'>&nbsp;</td></tr>";

					$i++;
				}
			return $s;
		}

	private function AddThemePOST()
		{
			if($this->System->checkPOST("topic","name","description") && is_numeric($_POST["topic"]))
				{

				$name=$this->System->toSafe($_POST["name"],1);

				$description=$this->System->toSafe($_POST["description"],1);

				$topic=$this->System->toSafe($_POST["topic"],1);

				$q=$this->System->dbo->select($this->table2,"id"," where topic_id='".$topic."' and name='".$name."' limit 1 offset 0");

				$q1=$this->System->dbo->select($this->table2,"id"," where topic_id='".$topic."' limit 1 offset 0");

				if(count($q)!=1 || count($q1)==1 || strlen($name)<5 || strlen($description)>300 )
					{
					$this->System->dbo->insert(
					$this->table2,
					array("name"=>$name,"topic_id"=>$topic,"description"=>$description,"created"=>"F|NOW()","author"=>$this->System->user->GetUserID()));
					
					/*"insert into `".$this->table2."` (`name`,`topic_id`,`description`,`created`,`author`) values ('".$name."','".$topic."','".$description."',NOW(),'".$this->System->user->GetUserID()."')");*/

					$code=2;
					}
				else
					{
					$code=3;
					}

				
				$this->System->base->sendHeader("forum-addtheme","code=".$code);

				}
		}


	public function AddTheme()
		{
			$f["title"]=$this->lang->get(10);

			$f["options"]=array("action"=>"","method"=>"post");

			$f["input"][0]=array("title"=>$this->lang->get(11),"type"=>"text","name"=>"name","size"=>"40");

			$f["input"][1]=array("title"=>$this->lang->get(12),"String"=>$this->topicSelection());

			$f["input"][2]=array("title"=>$this->lang->get(13),"type"=>"textarea","name"=>"description","class"=>"input","cols"=>80,"rows"=>4);

			$f["input"][3]=array("type"=>"Submit","name"=>"Submit","value"=>$this->lang->get(14));


			return $this->AddThemePOST().$this->System->base->FormGenerator($f);
		}

	public function DeleteThemeAdmin()
		{
			if(isset($_GET["thread"]) && is_numeric($_GET["thread"]))
				{
				$t=$this->System->toSafe($_GET["thread"],1);

					$f["title"]="Do you realy want to delete this theme (id".$t.") ?";

					$f["options"]=array("action"=>$this->B("DeleteThemeAdmin"),"method"=>"post");

					$f["input"][0]=array("type"=>"Submit","name"=>"Submit","value"=>"Yes");

					$f["input"][1]=array("type"=>"hidden","name"=>"thread","value"=>$t);

					if($this->System->checkPOST("thread","Submit"))
						{
							$topic=$this->System->dbo->select($this->table2,"topic_id"," where id='".$t."' ");

							$this->System->dbo->delete($this->table2,"where id='".$t."'");

							$this->System->dbo->delete($this->table3,"where theme_id='".$t."' ");

							return $this->System->base->BuildActionLink("forum-getthemesadmin","topic=".$topic[0]["topic_id"],"Theme Deleted. To List");
						}
					else return $this->System->base->FormGenerator($f);
				}

			else return "Please specify theme to be deleted )";

		}

	public function GetThemes()
		{
		if(isset($_GET["topic"]) && is_numeric($_GET["topic"]))
			{
				$t=$this->System->toSafe($_GET["topic"],1);

				$q=$this->System->dbo->select($this->table,"name","where id='".$t."' limit 1 offset 0");

				$name=$q[0]["name"];

				if(count($q)==0)return null;

				$q=$this->System->dbo->select($this->table2,"name,id,created","where topic_id='".$t."'");

				$s="<table width='95%' cellspacing='0' cellpadding='0'>";

				$s.="<tr><td colspan='4' id='tableheader'>".$name."</td></tr>";

				$i=0;

				while($i<count($q))
					{
						if($i==0)
						$s.="<tr><td id='subtheme'></td><td></td><td id='subtheme'>".$this->lang->get(5)."</td><td id='subtheme'>".$this->lang->get(6)."</td></tr>";

						$m=$this->System->dbo->select($this->table3,"COUNT(*)","where theme_id='".$q[$i]["id"]."'");

						$s.="<tr><td id='subtheme'><img src='img/th.png' border='0' /></td><td id='subtheme'>".$this->System->base->BuildActionLink("forum-getmessages","thread=".$q[$i]["id"],$q[$i]["name"])."</td><td id='subtheme'>".$m[0]["COUNT(*)"]."</td><td id='subtheme'>&rarr; ".$q[$i]["created"]."</td></tr>";

						$i++;

					}

				if($i==0)$s.="<tr><td colspan='4' id='subtheme'>".$this->lang->get(9)."</td></tr>";

				$s.="</table><br><br>";
			return $this->ForumHeader().$this->CodeListener().$s;

			}
			
		}

	public function GetThemesAdmin()
		{

		if(isset($_GET["topic"]) && is_numeric($_GET["topic"]))
			{
				$topic=$this->System->toSafe($_GET["topic"],1);
				
				$n=$this->System->dbo->select($this->table,"name","where id='".$topic."' limit 1 offset 0");
				
				if(count($n)==0)return "Topic not found";

				$n=$n[0]["name"];

				$q=$this->System->dbo->select($this->table2,"name,id","where topic_id='".$topic."'");

				$i=0;

				$_="Themes for Topic - ".$n." <br><table>";

				while($i<count($q))
					{
						$_.="<tr><td>".$this->System->base->BuildActionLink("forum-getthemespageadmin","thread=".$q[$i]["id"],$q[$i]["name"])."</td><td>".$this->System->base->BuildActionLink("forum-deletethemeadmin","thread=".$q[$i]["id"],"[ Delete ]")."</td></tr>";

						$i++;

					}
				return $_."</table>";
			}
		else return $this->lang->get(15);

		}

	public function GetThemesPageAdmin()
		{
			if(isset($_GET["thread"]) && is_numeric($_GET["thread"]))
				{
					$t=$this->System->toSafe($_GET["thread"],1);

					$q=$this->System->dbo->select($this->table2,"topic_id","where id='".$t."' ");

					$_=$this->GetWay($q[0]["topic_id"],$t)."<br><table>";

					$i=0;

					$q=$this->System->dbo->select($this->table3,"id,message,created,owner"," where theme_id='".$t."'");

					while($i<count($q))
						{

							$_.="<tr><td>".$q[0]["owner"]."</td><td>".$q[0]["message"]."</td><td>".$q[0]["created"]."</td><td>".$this->System->base->BuildActionLink("forum-deletemessagesadmin","id=".$q[0]["id"],"[ Delete ]")."</td></tr>";

							$i++;							
						}

					return $_."</table>";
					
				}
			else return "Please Specify A Theme )";
		}


	private function AddMessagePOST()
		{

		if(!isset($_GET["thread"]) || !is_numeric($_GET["thread"]) || !$this->A("AddMessage"))return null;

			if($this->System->checkPOST("postmessage","Submit","thread"))
				{
					$thread=$this->System->toSafe($_POST["thread"],1);

					if(!is_numeric($thread) || $thread!=$_GET["thread"]) return null;

					$message=$this->System->toSafe($_POST["postmessage"],1);

					$message=str_replace("qoute:","<div id=\"quote\">",$message);

					$message=str_replace(":endquote","</div>",$message);

					$this->System->dbo->insert($this->table3,array(
					"message"=>$message,"theme_id"=>$thread,"created"=>"F|NOW()","owner"=>$this->System->user->GetUserID())
					);

					
					$this->System->base->sendHeader("forum-getmessages","thread=".$thread."&code=0".(isset($_GET["page"])?"&page=".$_GET["page"]:null));
					
				}

		return true;
		}




	public function AddMessage()
		{

		if(!isset($_GET["thread"]) || !is_numeric($_GET["thread"]) || !$this->A("AddMessage"))return null;

		$f["options"]=array("action"=>"","method"=>"post");

		$f["input"][0]=array("type"=>"textarea","id"=>"addfield","cols"=>80,"rows"=>15,"name"=>"postmessage","class"=>"input");

		$f["input"][1]=array("type"=>"Submit","name"=>"Submit","value"=>$this->lang->get(16));

		$f["input"][2]=array("type"=>"hidden","name"=>"thread","value"=>$_GET["thread"]);

		$_="<table width='95%'><tr><td id='tableheader'>".$this->lang->get(16)."</td></tr>";
		$_.="<tr><td id='subtableheader' align='center'>".$this->System->base->FormGenerator($f)."</td></tr>";
		$_.="</table>";

		return $this->System->base->GetTinyMCE("forum").$_;
		}

	public function DeleteMessage()
		{
		if(!isset($_GET["message"]) || !is_numeric($_GET["message"]))
			{
				return $this->GetTopics();
			}

		$id=$this->System->toSafe($_GET["message"],1);

		$q=$this->System->dbo->select($this->table3,"owner,theme_id"," where mid='".$id."' limit 1 offset 0");

		if(count($q)==1 && $q[0]["owner"]==$this->System->user->GetUserID())
			{
				$this->System->dbo->delete($this->table3,"where mid='".$id."'");
				
				$this->System->base->sendHeader("forum-getmessages","thread=".$q[0]["theme_id"]."&code=1".(isset($_GET["page"])?"&page=".$_GET["page"]:null));
			}
		
		}

	private function CodeListener()
		{

		$m=null;

		if(isset($_GET["code"]) && is_numeric($_GET["code"]))
			{
				switch($_GET["code"])
					{
						case "0":$m=$this->lang->get(17);break;

						case "1":$m=$this->lang->get(18);break;

						case "2":$m=$this->lang->get(19);break;

						case "3":$m=$this->lang->get(20); break;
					}
			return ($m==null)?null:"<div id='forumcodemessage'><table width='".$this->width."'><tr><td id='codemessage' align='center'>".$m."</td></tr></table></div><br>";
			}

		}

	public function GetMessages()
		{

		if(isset($_GET["thread"]) && is_numeric($_GET["thread"]))
			{

				$this->AddMessagePOST();

				$t=$this->System->toSafe($_GET["thread"],1);

				$q=$this->System->dbo->select($this->table3,"COUNT(*)","where theme_id='".$t."' ");

				$q1=$this->System->dbo->select($this->table2,"topic_id","where id='".$t."' limit 1 offset 0");

				$topic=$q1[0]["topic_id"];

				$total=$q[0]["COUNT(*)"];

				$pages=(int)round($total/$this->messagesPerPage+0.459);

				$page=( isset($_GET["page"])
					&& is_numeric($_GET["page"])
					&& $_GET["page"]<=$pages
					&& $_GET["page"]>0
				)?$_GET["page"]:0;

				//$page=6;

				$q=$this->System->dbo->select("users,".$this->table2.",".$this->table3, users.id, ".$this->table2.".name ,".$this->table2.".author,".$this->table2.".description , ".$this->table3.".message,".$this->table3.".owner, ".$this->table3.".created,".$this->table3.".mid  ," where users.id=".$this->table3.".owner and ".$this->table2.".id='".$t."' and ".$this->table3.".theme_id='".$t."' order by ".$this->table3.".created desc limit  ".$this->messagesPerPage.",".($this->messagesPerPage*$page));

				$i=0;

				$_="<table width='".$this->width."' cellspacing='0' cellpadding='0'>";
				
				if(count($q)==0)$_.="<tr><td id='subtableheader'>".$this->lang->get(7)."</td></tr>";

				while($i<count($q))
					{

						if($i==0)
							{
								$_.="<tr><td colspan='2' id='tableheader' >".$this->lang->get(21).": ".$q[0]["name"]."</td></tr>";

								$_.="<tr><td colspan='2' id='subtableheader' align='right'>".$this->lang->get(4)." ".$total."  ".$this->System->base->Pages($pages,$page,$this->B("GetMessages"),"thread=".$t,"page","page","spage")."</td></tr>";

								if(strlen($q[0]["description"])>10)
								$_.="<tr><td id='messageleftside' valign='top'>".$this->CollectUserInfo($q[0]["author"])."</td><td id='messagerightsideauthor' valign='top'><div id='sp'>".$this->lang->get(22).":</div>".$q[0]["description"]."</td></tr><tr><td colspan='2'><span style='font-size:8px;'>&nbsp;</span></td></tr>";
							}

						$d=null;

						$qt=null;

						$r=rand(1000,999999);

						if($this->A("AddMessage"))
						$qt="<a href='javascript:void(0);' onclick='javascript:publish(\"".$r."\");' class='page'>".$this->lang->get(23)."</a>";

						if($this->System->user->GetUserID()==$q[$i]["owner"])
						$d=$this->System->base->BuildActionLink("forum-deletemessage","message=".$q[$i]["mid"],$this->lang->get(24),"page");

						$_.="<tr><td id='messageleftside' valign='top' width='115px'>".$this->CollectUserInfo($q[$i]["owner"])."</td>
						<td id='messagerightside' valign='top'><div align='right' class='dateview'>  &rarr; ".$q[$i]["created"]."</div><div id='".$r."'>".$q[$i]["message"]."</div>
						<br>
						</td></tr><tr><td colspan='2' id='messagerightside'><div align='right'>".$d." ".$qt."</div></td></tr><tr><td><span style='font-size:8px;'>&nbsp;</span></td></tr>";

						$i++;
					}
			return $this->ForumHeader().$this->CodeListener().$_."</table>".$this->AddMessage();
			}
		}

	private function CollectUserInfo($id)
		{
			if(!is_numeric($id))return null;

			$q1=$this->System->dbo->select("users","firstname,lastname,avatar"," where id='".$id."' limit 1 offset 0");

			if(count($q1)==0)return null;

			$s="<div align='center'>".$this->C($id,$q1[0]["nickname"])."</div><br>";

			$s.="<div align='center'>".$this->System->file->GetFoto($q1[0]["avatar"])."</div>";

			$s.="<div align='center'>".($this->System->session->CheckUserOnline($id)?"Online":"Offline")."</div>";

			$q2=$this->System->dbo->select($this->table3,"COUNT(*)","where owner='".$id."'");

			$s.="<div align='center'>".$this->lang->get(25).":".$q2[0]["COUNT(*)"]."</div><br>";
			

			return $s;
		}


	public function DeleteMessagesAdmin()
		{


			
		}

	/* Other private functions */

	private function GetWay($topic,$theme)
		{

		/*$q1=$this->System->dbo->select("select `name`,`id` from `".$this->table."` where `id`='".$topic."' ");

		$q2=$this->System->dbo->select("select `name`,`id` from `".$this->table2."`  where `id`='".$theme."' ");

		if(count($q1) == 0 || count($q2)==0 )return null;

		$a=$this->System->base->BuildActionLink($this->B("GetTopicsAdmin"),null,"Forum");

		$a1=$this->System->base->BuildActionLink($this->B("GetThemesAdmin"),"topic=".$q1[0]["id"],$q1[0]["name"]);

		$a2=$this->System->base->BuildActionLink($this->B("GetThemesPageAdmin"),"thread=".$q2[0]["id"],$q2[0]["name"]);

		return $a." >>> ".$a1." >>> ".$a2;*/
		}

	private function WayTable($a=0,$b=0)
		{
		return "";//"<table width='".$this->width."'><tr><td id='subtheme' align='right'>".$this->Way($a,$b)."</td></tr></table><br>";
		}


	private function Way($topic=0,$theme=0)
		{

		/*$q1=$this->System->dbo->select("select `name`,`id` from `".$this->table."` where `id`='".$topic."' ");

		$q2=$this->System->dbo->select("select `name`,`id` from `".$this->table2."`  where `id`='".$theme."' ");

		$a=$this->System->base->BuildActionLink($this->B("GetTopics"),null,"Forum");

		if(count($q1) == 0 || ($topic==0 && $theme==0))return "<b>".$a."</b>";

		$a1=$this->System->base->BuildActionLink($this->B("GetThemes"),"topic=".$q1[0]["id"],$q1[0]["name"]);

		if(count($q2) == 0 || ($theme==0) ) return "<b>".$a."</b> <span class='orange'>>></span> <b>".$a1."</b>";

		$a2=$this->System->base->BuildActionLink($this->B("GetMessages"),"thread=".$q2[0]["id"],$q2[0]["name"]);

		return "<b>".$a."</b> <span class='orange' >>></span> <b>".$a1."</b> <span class='orange' >>> </span> <b>".$a2."</b>";
		*/
		return "";	
		}

	public function ForumConfiguration()
		{



			
		}

	public function LoadForumConfiguration()
		{


			
		}



	public function install()
		{
		
		$t["name"]="mod_forum_topics";
		$t["field"][]=array("name"=>"id","type"=>"int_auto");
		$t["field"][]=array("name"=>"name","type"=>"char");
		$t["field"][]=array("name"=>"created","type"=>"datetime");
		$t["field"][]=array("name"=>"views","type"=>"int");
		$t["key"][]=array("field"=>"id");
		$t["key"][]=array("field"=>"name");
		
		$this->System->dbo->createtable($t);
		
		unset($t);
		
		$t["name"]="mod_forum_themes";
		$t["field"][]=array("name"=>"id","type"=>"int_auto");
		$t["field"][]=array("name"=>"name","type"=>"char");
		$t["field"][]=array("name"=>"topic_id","type"=>"int");
		$t["field"][]=array("name"=>"created","type"=>"datetime");
		$t["field"][]=array("name"=>"views","type"=>"int");
		$t["field"][]=array("name"=>"owner","type"=>"int");
		$t["key"][]=array("field"=>"name");
		$t["ukey"][]=array("field"=>"id");
		
		$this->System->dbo->createtable($t);
		unset($t);
		
		$t["name"]="mod_forum_messages";
		$t["field"][]=array("name"=>"id","type"=>"int_auto");
		$t["field"][]=array("name"=>"message","type"=>"text");
		$t["field"][]=array("name"=>"theme_id","type"=>"int");
		$t["field"][]=array("name"=>"owner","type"=>"int");
		$t["field"][]=array("name"=>"created","type"=>"datetime");
		$t["key"][]=array("field"=>"theme_id");
		$t["key"][]=array("field"=>"owner");
		$t["ukey"][]=array("field"=>"id");		
		
		$this->System->dbo->createtable($t);		
		unset($t);
		
		}

	public function uninstall()
		{
		
		$this->System->dbo->direct("drop table if exists mod_forum_topics");
		
		$this->System->dbo->direct("drop table if exists mod_forum_themes");
		
		$this->System->dbo->direct("drop table if exists mod_forum_messages");

		}
		
	public function langterms()
		{
		$l["GetTopics"][0]=array("lang"=>"ua","value"=>"Форум","tmpvalue"=>"Форум");
		$l["GetTopics"][1]=array("lang"=>"ru","value"=>"Форум","tmpvalue"=>"Форум");
		$l["GetTopics"][2]=array("lang"=>"en","value"=>"Forum","tmpvalue"=>"Forum");

		$l["GetTopicsAjax"][0]=array("lang"=>"ua","value"=>"Форум","tmpvalue"=>"Форум");
		$l["GetTopicsAjax"][1]=array("lang"=>"ru","value"=>"Форум","tmpvalue"=>"Форум");
		$l["GetTopicsAjax"][2]=array("lang"=>"en","value"=>"Forum","tmpvalue"=>"Forum");

		return $l;
		}


	}
?>
